use actix_web::{Responder, HttpResponse, HttpRequest, Error};
use futures::future::{ready, Ready};
use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize};
use rbatis::crud::CRUD;
use rbatis::rbatis::Rbatis;
use rbatis::Error as rError;

#[crud_table( id_name:id |  id_type:String |  table_name:good |  table_columns:id,name,freight_template_id,remark,create_time,update_time,delete_flag )]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Good{
    pub id: Option<String>,
    pub name: Option<String>,
    pub freight_template_id: Option<String>,
    pub remark: Option<String>,
    pub create_time: Option<NaiveDateTime>,
    pub update_time: Option<NaiveDateTime>,
    pub delete_flag: Option<i32>,
}

impl Responder for Good {
    type Error = Error;
    type Future = Ready<Result<HttpResponse, Error>>;

    fn respond_to(self, _req: &HttpRequest) -> Self::Future {
        let body = serde_json::to_string(&self).unwrap();

        // Create response and set content type
        ready(Ok(HttpResponse::Ok()
            .content_type("application/json")
            .body(body)))
    }
}